home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1993 December
/
PSL Monthly Shareware CD-ROM (December 1993).iso
/
prgmming
/
dos
/
pascal
/
fastkey.exe
/
FASTKEY.DOC
< prev
next >
Wrap
Text File
|
1992-12-11
|
15KB
|
265 lines
FastKey v1.1 for Turbo Pascal 6.0
FastKey v1.0 for Turbo C
Copyright 1992 by Steve Holley.
Opening Rambling:
While writing my first arcade game for the IBM PC, I discovered that
the standard keyboard routines that I had available were not good
enough. I needed a method to handle the key presses as soon as the
program was ready for them. There was also a slight delay that
occurred when you switch between keys that you have been holding
down. After much coding and research, I developed a routine that
would monitor the keyboard with enough speed to please me. At the
suggestion of a good friend, and since I was unable to find a similar
product while developing my code (that would have saved me a lot of
time), I have decided to release a unit for Turbo Pascal 6.0 that
improves keyboard handling. Special thanks to Curtis Keisler for the
conversion of the assembler code to a Turbo Pascal Unit and for his
suggestions.
What FastKey is:
FastKey is an interrupt driven routine that monitors the keyboard,
keeping track of which keys are pressed and which are not. At any
given time you can check to see which keys are pressed since the
interrupt occurs asynchronous to the rest of your program. This may
sound strange but for arcade games it is a good way of handling the
keyboard. It allows the program to process keyboard input as soon as
the program is ready for it. I do not recommend this routine for
standard business applications since it does not buffer the input or
process the keyboard in the same way that the normal interrupt does.
Also, any TSR (Terminate and Stay Resident) programs that use the
keyboard interrupt will not work with FastKey. In general, as soon
as you install FastKey your program has the whole computer to itself.
As soon as FastKey is removed, the TSRs will work properly. While
FastKey is installed the following Turbo Pascal procedures and
functions should not be used: Readln, KeyPressed and ReadKey. If you
attempt to uses these routines the computer may lock-up.
Disclaimer:
I wish that I did not have to include this section but due to the
highly "sue-able" state of the world, the following section is,
unfortunately, required. FastKey is distributed "as is", with no
guarantee that it will work properly in any or all programs or
combinations of hardware. The Author assumes no liability for any
damages, financial, software or hardware, caused by the use, misuse,
or modification of this product, nor is he liable if part of a
passing 747 falls on your house destroying your computer while using
this product.
Distribution:
You may freely distribute unmodified copies of the FastKey package
(all files listed in the README file) so long as any fee charged is
for distribution costs only. Commercial distribution strictly
prohibited.
System Requirements:
1. IBM PC/XT/AT/Jr/PS/2 or 100%
2. Turbo Pascal(tm) v6.0 or greater
Turbo Pascal and Turbo C are registered trademarks of BORLAND International.
Compuserve is a registered trademark of Compuserve Incorporated. Usage:
FastKey is easy to use. To make it available to your program just
include FastKey in your Uses section at the start of your program.
See the Turbo Pascal reference manual for help with the Uses command.
Only four routines are used in the FastKey unit. Each is detailed
below. For an example of how to use FastKey, examine DEMO2.PAS.
Procedure InstallFastKey;
Function FastKeyInstalled : Boolean;
Function Pressed (KeyCode : Byte) : Boolean;
Function FastKeyPressed : Boolean;
Procedure UnInstallFastKey;
InstallFastKey
Before FastKey can be used, it must first be installed. At the start
of your program, call InstallFastKey. I recommend that you do this
in your main program block or in your initialization routine. That's
all there is to the installation. As soon as it is installed you can
begin to use Pressed to determine which keys are pressed.
FastKeyInstalled
The function FastKeyInstalled is used to determine if FastKey has
been installed. It will return true if FastKey has been installed.
You probably will not use it but it is there if you need it.
Pressed(KeyCode)
Pressed will return a boolean value indicating the status of any key
on the keyboard. See Key Code Table at the end of this document for
a list of each of the keys and their key code. A value of TRUE
indicates that the key is pressed. A value of FALSE means it is not.
Note that any combination of keys may be checked by successive calls
to pressed. For example to determine if both Cursor Up and Cursor
Left are pressed use the following line:
IF Pressed(FKUP) AND Pressed(FKLEFT) THEN some action
Several useful key combinations are possible by combining boolean
expressions with Pressed. It is also possible to check that a key is
not pressed at the same time as another key is pressed. If the
cursor left and right controlled a ships movement on screen, you
would not want to be able to move if both keys were pressed. The
following lines move the ship and insure that only legal key
combinations are allowed.
IF Pressed(FKLEFT) AND NOT Pressed(FKRIGHT) THEN move left
IF Pressed(FKRIGHT) AND NOT Pressed(FKLEFT) THEN move right
FastKeyPressed
The function FastKeyPressed is used to see if any key is currently
pressed, perhaps to see if there is a need to check for an complex
key combination. It is used exactly the same as the Turbo Pascal
function Keypressed.
UnInstallFastKey
It is very important that you remove FastKey from the interrupt table
before you exit your program. Failure to do so will result in your
computer locking up so tightly that you will have to use the big red
button to bring it back to life. This should be one of the last
instructions executed, perhaps in the main program block or a routine
that resets the computer. Registration:
FastKey is distributed as shareware. The registration fee for
continued use of the unit is proper credit. If you use these
routines in a program, please include something like "FASTKEY
Keyboard Routines by Steve Holley" in the title screen or
documentation, and just drop me a note at the following address. I'd
like to see what people have been able to do with these routines. If
you would like to make a contribution to the author for the use of
the unit, any amount will be accepted (and is encouraged if you
charge a fee for your software that uses FastKey. You decide what is
fair since only you know how important these routines were to your
program.).
All source code is available for $20.00. This includes the original
.ASM file, an .OBJ file compiled with Borland TASM 2.0 (the best
assembler on the market), the source code for the Turbo Pascal Unit
that you already have and the C source code for FastKey, and the
source & executable for a program to display the key codes generated
by the keyboard. All source code is heavily commented to make
modification and understanding easier. The source code will come in
handy if/when TP 7.0 comes out and the unit formats are again
changed, or you want to add support for a new or non-standard
keyboard. With the assembler source code it should